| Conditions | 1 |
| Paths | 8 |
| Total Lines | 110 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var newUserDates = []; |
||
| 58 | $(document).ready(function () { |
||
| 59 | // count how many times in each date |
||
| 60 | new Clipboard('.copy-link'); |
||
| 61 | updateBest(); |
||
| 62 | $('.delete-poll').click(function(){ |
||
| 63 | deletePoll(this); |
||
| 64 | }); |
||
| 65 | |||
| 66 | $('#switchDetails').click(function(){ |
||
| 67 | switchSidebar(); |
||
| 68 | }); |
||
| 69 | |||
| 70 | $('#closeDetails').click(function(){ |
||
| 71 | OC.Apps.hideAppSidebar(); |
||
| 72 | }); |
||
| 73 | |||
| 74 | $('.poll.avatardiv').each(function(i, obj) { |
||
| 75 | $(obj).avatar(obj.title, 32); |
||
| 76 | }); |
||
| 77 | |||
| 78 | $('.vote.time').each(function() { |
||
| 79 | var extendedDate = new Date($(this).attr("data-value-utc").replace(/ /g,"T")+"Z"); //Fix display in Safari and IE |
||
| 80 | |||
| 81 | $(this).find('.month').text(extendedDate.toLocaleString(window.navigator.language, {month: 'short'})); |
||
| 82 | $(this).find('.day').text(extendedDate.toLocaleString(window.navigator.language, {day: 'numeric'})); |
||
| 83 | $(this).find('.dayow').text(extendedDate.toLocaleString(window.navigator.language, {weekday: 'short'})); |
||
| 84 | $(this).find('.time').text(extendedDate.toLocaleTimeString(window.navigator.language, {hour: 'numeric', minute:'2-digit', timeZoneName:'short'})); |
||
| 85 | |||
| 86 | }); |
||
| 87 | |||
| 88 | $('#submit_finish_vote').click(function() { |
||
| 89 | var form = document.finish_vote; |
||
| 90 | var ac = document.getElementById('user_name'); |
||
| 91 | if (ac !== null) { |
||
| 92 | if(ac.value.length >= 3){ |
||
| 93 | form.elements.userId.value = ac.value; |
||
| 94 | } else { |
||
| 95 | alert(t('polls', 'You are not registered.\nPlease enter your name to vote\n(at least 3 characters).')); |
||
| 96 | return; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | var check_notif = document.getElementById('check_notif'); |
||
| 100 | var newUserDates = [], newUserTypes = []; |
||
| 101 | $(".poll-cell.active").each(function() { |
||
| 102 | if($(this).hasClass('no')) { |
||
| 103 | newUserTypes.push(0); |
||
| 104 | } else if ($(this).hasClass('yes')){ |
||
| 105 | newUserTypes.push(1); |
||
| 106 | } else if($(this).hasClass('maybe')){ |
||
| 107 | newUserTypes.push(2); |
||
| 108 | } else { |
||
| 109 | newUserTypes.push(-1); |
||
| 110 | } |
||
| 111 | if (isNaN($(this).attr('data-value'))) { |
||
| 112 | newUserDates.push($(this).attr('data-value')); |
||
| 113 | } else { |
||
| 114 | newUserDates.push(parseInt($(this).attr('data-value'))); |
||
| 115 | } |
||
| 116 | }); |
||
| 117 | form.elements.dates.value = JSON.stringify(newUserDates); |
||
| 118 | form.elements.types.value = JSON.stringify(newUserTypes); |
||
| 119 | form.elements.receiveNotifications.value = (check_notif && check_notif.checked) ? 'true' : 'false'; |
||
| 120 | form.elements.changed.value = valuesChanged ? 'true' : 'false'; |
||
| 121 | form.submit(); |
||
| 122 | }); |
||
| 123 | |||
| 124 | $('#submit_send_comment').click(function(e) { |
||
| 125 | e.preventDefault(); |
||
| 126 | var form = document.send_comment; |
||
| 127 | var ac = document.getElementById('user_name_comm'); |
||
| 128 | if (ac !== null) { |
||
| 129 | if(ac.value.length >= 3){ |
||
| 130 | form.elements.userId.value = ac.value; |
||
| 131 | } else { |
||
| 132 | alert(t('polls', 'You are not registered.\nPlease enter your name to vote\n(at least 3 characters).')); |
||
| 133 | return; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | var comment = document.getElementById('commentBox'); |
||
| 137 | if(comment.value.trim().length <= 0) { |
||
| 138 | alert(t('polls', 'Please add some text to your comment before submitting it.')); |
||
| 139 | return; |
||
| 140 | } |
||
| 141 | var data = { |
||
| 142 | pollId: form.elements.pollId.value, |
||
| 143 | userId: form.elements.userId.value, |
||
| 144 | commentBox: comment.value.trim() |
||
| 145 | }; |
||
| 146 | $('.new-comment .icon-loading-small').show(); |
||
| 147 | $.post(form.action, data, function(data) { |
||
| 148 | $('.comments .comment:first').after('<div class="comment"><div class="comment-header"><span class="comment-date">' + data.date + '</span>' + data.userName + '</div><div class="wordwrap comment-content">' + data.comment + '</div></div>'); |
||
| 149 | $('.new-comment textarea').val('').focus(); |
||
| 150 | $('.new-comment .icon-loading-small').hide(); |
||
| 151 | updateCommentsCount(); |
||
| 152 | }).error(function() { |
||
| 153 | alert(t('polls', 'An error occurred, your comment was not posted.')); |
||
| 154 | $('.new-comment .icon-loading-small').hide(); |
||
| 155 | }); |
||
| 156 | }); |
||
| 157 | |||
| 158 | $(".share input").click(function() { |
||
| 159 | $(this).select(); |
||
| 160 | }); |
||
| 161 | |||
| 162 | $('.toggle-cell').tooltip(); |
||
| 163 | $('.time-slot').tooltip(); |
||
| 164 | $('.avatardiv').tooltip(); |
||
| 165 | updateCounters(); |
||
| 166 | |||
| 167 | }); |
||
| 168 | |||
| 198 |